package com.jjb.www.ui.activity;

import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;

import android.os.Bundle;

import com.bumptech.glide.load.MultiTransformation;
import com.bumptech.glide.load.resource.bitmap.CenterCrop;
import com.bumptech.glide.load.resource.bitmap.RoundedCorners;
import com.hjq.http.EasyHttp;
import com.hjq.http.listener.HttpCallback;
import com.hjq.shape.view.ShapeImageView;
import com.hjq.shape.view.ShapeTextView;
import com.hjq.widget.layout.WrapRecyclerView;
import com.jjb.www.R;
import com.jjb.www.app.AppActivity;
import com.jjb.www.http.api.CompleteDetailApi;
import com.jjb.www.http.api.GraduationApi;
import com.jjb.www.http.glide.GlideApp;
import com.jjb.www.http.model.HttpData;
import com.jjb.www.ui.adapter.ClxxAdapter;
import com.jjb.www.ui.adapter.JzpxAdapter;
import com.jjb.www.ui.adapter.ZxxxAdapter;

/**
 *    author : Android CRG
 *    github : https://github.com/getActivity/AndroidProject
 *    time   : 2018/10/18Evaluation
 *    desc   : 学时记录
 */
public class CompleteDetailActivity extends AppActivity {
    private String id;
    private ShapeTextView mTvPostName;
    private ShapeImageView mImgZs;
    private ShapeTextView mTvCertNum;
    private ShapeTextView mTvCompleteTime;
    private ShapeTextView mTvZxxx;
    private ShapeTextView mTvZxxxNumer;
    private WrapRecyclerView mRvListZxxx;
    private ShapeTextView mTvJzpx;
    private ShapeTextView mTvJzpxNumber;
    private WrapRecyclerView mRvListJzpx;
    private ShapeTextView mTvClxx;
    private ShapeTextView mTvClxxNumber;
    private WrapRecyclerView mRvListClxx;
    private ZxxxAdapter zxxxAdapter;
    private JzpxAdapter jzpxAdapter;
    private ClxxAdapter clxxAdapter;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_complete_detail;
    }

    @Override
    protected void initView() {
        mTvPostName = findViewById(R.id.tv_post_name);
        mImgZs = findViewById(R.id.img_zs);
        mTvCertNum = findViewById(R.id.tv_cert_num);
        mTvCompleteTime = findViewById(R.id.tv_complete_time);
        mTvZxxx = findViewById(R.id.tv_zxxx);
        mTvZxxxNumer = findViewById(R.id.tv_zxxx_numer);
        mRvListZxxx = findViewById(R.id.rv_list_zxxx);
        mTvJzpx = findViewById(R.id.tv_jzpx);
        mTvJzpxNumber = findViewById(R.id.tv_jzpx_number);
        mRvListJzpx = findViewById(R.id.rv_list_jzpx);
        mTvClxx = findViewById(R.id.tv_clxx);
        mTvClxxNumber = findViewById(R.id.tv_clxx_number);
        mRvListClxx = findViewById(R.id.rv_list_clxx);

        mRvListZxxx.setLayoutManager(new LinearLayoutManager(getContext()));
        mRvListJzpx.setLayoutManager(new LinearLayoutManager(getContext()));
        mRvListClxx.setLayoutManager(new LinearLayoutManager(getContext()));

        zxxxAdapter = new ZxxxAdapter(getContext());
        jzpxAdapter = new JzpxAdapter(getContext());
        clxxAdapter = new ClxxAdapter(getContext());

        mRvListZxxx.setAdapter(zxxxAdapter);
        mRvListJzpx.setAdapter(jzpxAdapter);
        mRvListClxx.setAdapter(clxxAdapter);
    }

    @Override
    protected void initData() {
        id = getString("id");
        EasyHttp.get(this)
                .api(new CompleteDetailApi()
                        .setId(id))
                .request(new HttpCallback<HttpData<CompleteDetailApi.Bean>>(this) {

                    @Override
                    public void onSucceed(HttpData<CompleteDetailApi.Bean> data) {
                        CompleteDetailApi.Bean.InfoDTO infoDTO = data.getData().getInfo();
                        mTvPostName.setText(infoDTO.getPost_name());
                        GlideApp.with(getContext())
                                .load(infoDTO.getImg())
                                .transform(new MultiTransformation<>(new CenterCrop(), new RoundedCorners((int) getResources().getDimension(R.dimen.dp_4))))
                                .into(mImgZs);
                        mTvCertNum.setText("证书编号："+infoDTO.getCert_num());
                        mTvCompleteTime.setText("结业时间："+infoDTO.getComplete_time());

                        mTvZxxx.setText(data.getData().getCourse_log_list().getTitle());
                        mTvZxxxNumer.setText("("+data.getData().getCourse_log_list().getScore()+")");
                        zxxxAdapter.setData(data.getData().getCourse_log_list().getList());

                        mTvJzpx.setText(data.getData().getMech_log_list().getTitle());
                        mTvJzpxNumber.setText("("+data.getData().getMech_log_list().getScore()+")");
                        jzpxAdapter.setData(data.getData().getMech_log_list().getList());

                        mTvClxx.setText(data.getData().getPromise_log_list().getTitle());
                        mTvClxxNumber.setText("("+data.getData().getPromise_log_list().getScore()+")");
                        clxxAdapter.setData(data.getData().getPromise_log_list().getList());
                    }

                });
    }
}